//引入接口
import { reqGetSearchInfo } from '@/api';

//search模块的配置项
const state = {
    // 搜索数据 当没有网络时undefined,防止报错
    searchList:{}||undefined,
};
const mutations = {
    GETSEARCHLIST(state,searchList){
           state.searchList = searchList;
    }
};
const actions = {  
    async getSearchList({commit},params){ 
        //当前这个reqGetSearchInfo需要个传参 用户派发action时传递进来,至少是个空对象
      let res = await reqGetSearchInfo(params);
      if(res.code == 200){
        commit("GETSEARCHLIST",res.data);
      }
    }
};
//计算属性,在项目里面为了简化数据而生
const getters = {
    //state 第一个参数当前仓库里的state
    goodsList(state){
       return state.searchList.goodsList || []
    },
    trademarkList(state){
        return state.searchList.trademarkList ||[];
    },
    attrsList(state){
        return state.searchList.attrsList||[];
    }
};
export default {
    namespaced:true,
    state,
    mutations,
    actions,
    getters,
}